# 导入webdriver包
from selenium import webdriver
# 引用By方法
from selenium.webdriver.common.by import By
# 导入Service用于定位浏览器/驱动路径
from selenium.webdriver.edge.service import Service
# 导入ActionChains类
from selenium.webdriver.common.action_chains import ActionChains
# 导入框架
import unittest
# 导入时间模块
import time


# 定义类
class TestDown(unittest.TestCase):
    def setUp(self):
        # 正确引用service对象初始化浏览器
        self.service = Service(executable_path=r'E:\pycharm\Projects\华测读书屋\msedgedriver.exe')
        # 定义浏览器
        self.driver = webdriver.Edge(service=self.service)


        # 窗口最大化
        self.driver.maximize_window()
        # 等待时长
        self.driver.implicitly_wait(5)

# 登录
    def test_login(self):
        self.driver.get("http://novel.hctestedu.com/")
        self.driver.find_element(By.CLASS_NAME,"mr15").click()
        self.driver.find_element(By.NAME,"txtUName").click()
        self.driver.find_element(By.NAME, "txtUName").send_keys("19956845963")
        self.driver.find_element(By.ID,"txtPassword").click()
        self.driver.find_element(By.ID, "txtPassword").send_keys("123456")
        self.driver.find_element(By.XPATH,"/html/body/div[2]/div/div[1]/form/ul/li[5]/input").click()
        time.sleep(2)

    # 添加
    def test_shujia(self):
        self.test_login()
        self.driver.find_element(By.LINK_TEXT,'娇女攻略').click()
        # self.driver.find_element(By.LINK_TEXT,'加入书架').click()
        self.driver.find_element(By.CLASS_NAME,'sj_link').click()
        self.driver.find_element(By.XPATH,'/html/body/div[2]/div/div[2]/div/div[2]/table/tbody/tr/td[5]/a').click()
        self.driver.find_element(By.LINK_TEXT,'评论').click()
        target_element = self.driver.find_element(By.NAME,'txtComment').send_keys("这本书真好看")


        time.sleep(3)

    def teatDown(self):
        self.driver.quit()
if __name__ == '__main__':
    unittest.main()